package com.ers.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;

import com.ers.dao.CompanyDao;
import com.ers.model.Company;
import com.ers.model.Photo;

public class CompanyDaoImpl implements CompanyDao{
	private SessionFactory sessionFactory;	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public void save(Company c) {
		sessionFactory.getCurrentSession().save(c);
		sessionFactory.getCurrentSession().createQuery("update HR hr set hr.isvalid = true where hr.id = "+c.getHr().getId());
	}
	@Override
	public void update(Company company) {
		sessionFactory.getCurrentSession().saveOrUpdate(company);
	}
	@Override
	public List<Photo> load(int id) {
		List<Photo> photos = sessionFactory.getCurrentSession().createCriteria(Photo.class).add(Restrictions.eq("company.id", id)).list();
		return photos;
	}

}
